import * as notifyRecordModel from '../../models/notify_record';
import { ValidException } from '../../helps/exception';

export function* add({ robot_id, type, module, module_id, duration, percent }) {
  if (!robot_id) throw ValidException('Robot参数错误');
  if (type !== 'spell' && type !== 'read') throw ValidException('类型错误：spell、read');
  if (type === 'spell') {
    if (module !== 'letter' && module !== 'word') throw ValidException('spell模块错误：letter，word');
  } else if (type === 'read') {
    if (module !== 'book_album') throw ValidException('read模块错误：book_album');
  }
  if (parseInt(duration, 10) < 0) throw ValidException('时长为空');
  if (parseInt(percent, 10) < 0) throw ValidException('百分比为空');
  yield notifyRecordModel.add({ robot_id, type, module, module_id, duration, percent });
  return {};
}

export function* test() {
  return null;
}
